package com.zhanglijie.improve.atomic.six;

import java.util.concurrent.atomic.LongAccumulator;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/9/10 0010 23:55
 */
public class TestLongAccumulator {
    static LongAccumulator accumulator =new LongAccumulator((x,y)->x*y,1);
    public static void sum(int num){
        accumulator.accumulate(num);//1*2  2*2  4*2  =1024
        System.out.println(Thread.currentThread().getName()+" 当前最终值 ="+accumulator.get());
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                sum(2);
            },"thread"+i).start();
        }
    }
}
